#include<iostream>
#include<cstring>
using namespace std;
int arr[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
int brr[13] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };
char str[8][10] = { "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" };
bool judge(int n)
{
	if (n % 400 == 0 || n % 100 != 0 && n % 4 == 0) {
		return 1;
	}
	return 0;
}
int main()
{
	int y, m, d;
	while (cin >> y >> m >> d) {
		if (judge(y)) {
			if (d > brr[m] || m <= 0 || d <= 0 || m >= 13) {
				cout << "illegal" << endl;
				continue;
			}
		}	
		else {
			if (d > arr[m] || m <= 0 || d <= 0 || m >= 13) {
				cout << "illegal" << endl;
				continue;
			}	
		}
		int sum = 0;
		for (int i = 1; i < y; i++) {
			if (judge(i)) {
				sum += 366;
			}
			else {
				sum += 365;
			}
			sum %= 7;
		}
		for (int i = 1; i < m; i++) {
			if (judge(y)) {
				sum += brr[i];
			}
			else {
				sum += arr[i];
			}
			sum %= 7;
		}
		sum += d;
		sum %= 7;
		cout << str[sum] << endl;
	}
	return 0;
}